<?php
/*include "classes/conexao.class.php";
$bd = 'getbo';
$conexao = new Conexao($bd);*/
$link = sybase_connect('getbo', 'carga', 'carga2006') or die("Could not connect !");
echo "Connected successfully <br/>";
$db = sybase_select_db('getbo', $link);
echo "Database selected<br/>";
$sql = "select distinct
	dateformat(dt_referencia, 'yyyymm') ano_mes,
	max(case when ds_indicador = 'BASE INSTALADA' then vl_indicador else null end) as base_instalada,
	max(case when ds_indicador = 'BASE ATIVA' then vl_indicador else null end) as base_ativa,
	(max(case when ds_indicador = 'BASE ATIVA' then vl_indicador else null end) / max(case when ds_indicador = 'BASE INSTALADA' then vl_indicador else null end)*100) as percentual

from
	dba.indicadores_estrategicos
group by
	dateformat(dt_referencia, 'yyyymm')";
echo $sql;
$rs = sybase_query($sql, $link);
echo "Query executed<br/>";
print_r(sybase_fetch_array($rs));
while ($linha = sybase_fetch_assoc($rs)) {
	$mes = $linha["ano_mes"];
	$bi = $linha["base_instalada"];
	$ba = $linha["base_ativa"];
	$perc = $linha["percentual"];
	
	echo $mes . ' ' . $bi . ' ' . $ba . ' ' . $perc . '<br/>';
}
sybase_close($link);
?>
